import router from '@/router';
import { watch } from 'vue';
import { reactive } from 'vue';
import { useRouter } from 'vue-router';
export default function importConfigFunction() {
  const base = reactive<any>({
    itemDom: [],
  });

  const gotoBack = (param) => {
    const currentRouter = router.currentRoute.value;
    if (currentRouter.name != param.name) {
      router.push(param.name);
    }
  };

  const init = () => {
    const router = useRouter();
    // 监听当前路由
    watch(
      () => router.currentRoute.value,
      (newValue: any) => {
        const data = newValue.matched.map((item: any) => {
          return {
            ...item,
            query: newValue.query,
          };
        });
        base.itemDom = data;
      },
      { immediate: true },
    );
  };

  const backspacePage = () => {
    router.go(-1);
  };
  return {
    base,
    gotoBack,
    init,
    backspacePage,
  };
}
